//file: Tests.java
import java.util.*;
import java.io.*;
import java.util.regex.*;



public class Tests {
	public static void main(String[] args) throws Exception
	{
		System.out.println("---------------");
		System.out.println("Testing split()");
		System.out.println("---------------");
		String text = "4231, Java Programming, 1000.00";
		String [] fields = text.split("\\s*,\\s*");
		for(String s : fields){
			System.out.println(s);
		}

		System.out.println("-----------------");
		System.out.println("Testing Scanner");
		System.out.println("-----------------");
		Scanner fileScanner = new Scanner(
			new File(".", "Message.properties") );
		fileScanner.useDelimiter( "\\s*=\\s*" );
		int print_id=1;
		while( fileScanner.hasNext( ) ) {
			String s = fileScanner.next( );
			System.out.println(print_id);
			System.out.println(s);
			print_id++;
		}

		System.out.println("-----------------------");
		System.out.println("Testing StringTokenizer");
		System.out.println("-----------------------");
		String sentence = "Now is the time for all good men (and women)...";
		StringTokenizer st = new StringTokenizer( sentence );
		print_id = 1;
		while ( st.hasMoreTokens( ) ) {
			String word = st.nextToken( );
			System.out.println(print_id);
			System.out.println(word);
			print_id++;
		}

		System.out.println("-------------");
		System.out.println("Testing regex");
		System.out.println("-------------");
		String text_to_parse="A horse is a horse, of course of course...";
		String pattern="horse|course";
		Matcher matcher = Pattern.compile( pattern ).matcher( text_to_parse );
		while ( matcher.find( ) ) { // As long as the matcher finds something...
			System.out.println("Matched: '"
				+matcher.group( ) // Retrieve the matched text
				+"' at position "+matcher.start( ) ); // Retrieve the starting character position
		}
	}
}
